﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class Camara2D
    {
        Vector2 position;

        float zoom;

        float rotation;

        Matrix transform;

        public Camara2D()
        {
            position = Vector2.Zero;
            zoom = 1.0f;
            rotation = 0.0f;
            transform = Matrix.Identity;
        }

        public float Zoom
        {
            get {return zoom;}
            set
            {
                zoom = value; 
                if (zoom < 0.1f) zoom = 0.1f;
            }
        }

        public float Rotation
        {
            get {return rotation;}

            set { rotation = value;}
        }

        public Vector2 Position
        {
            get {return position;}

            set {position = value;}
        }

        public void Move(Vector2 amount)
        {
            position += amount;
        }

        public Matrix get_transformation(GraphicsDeviceManager graphicsDevice)
        {
            transform = Matrix.CreateTranslation(new Vector3(-position.X, -position.Y, 0))
                * Matrix.CreateRotationZ(rotation)
                * Matrix.CreateScale(new Vector3(Zoom, Zoom, 0))
                * Matrix.CreateTranslation(new Vector3(graphicsDevice.PreferredBackBufferWidth * 0.5f, graphicsDevice.PreferredBackBufferHeight * 0.5f, 0));

            return transform;
        }

    }
}
